#region

using System;
using System.ComponentModel.DataAnnotations;
using VinhSon.Intranet.Bussiness;

#endregion

namespace VinhSon.Intranet.Models
{
    [Serializable]
    public partial class UserModel
    {
        #region Constructor

        public UserModel()
        {
        }

        public UserModel(User value)
        {
            Id = value.Id;
            Name = value.Name;
            Username = value.Username;
            Remark = value.Remark;
            IsActivated = value.IsActivated ?? false;
            IsLockedOut = value.IsLockedOut ?? false;
        }

        #endregion

        #region Fields

        private Int32 _Id;

        private Boolean _IsActivated;

        private Boolean _IsLockedOut;

        private String _Password;

        private String _Remark;

        private String _Username;

        private String _Name;

        #endregion

        #region Properties

        //[Required]
        //[Range(0, 0]
        //[StringLength(0)]
        public Int32 Id
        {
            get
            {
                return _Id;
            }
            set
            {
                _Id = value;
            }
        }

        [Required]
        //[Range(0, 0]
        [StringLength(50)]
        public String Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }

        [Required]
        //[Range(0, 0]
        [StringLength(50)]
        public String Username
        {
            get
            {
                return _Username;
            }
            set
            {
                _Username = value;
            }
        }

        //[Required]
        //[Range(0, 0]
        [DataType(DataType.Password)]
        [StringLength(128)]
        public String Password
        {
            get
            {
                return _Password;
            }
            set
            {
                _Password = value;
            }
        }

        //[Required]
        //[Range(0, 0]
        [StringLength(100)]
        public String Remark
        {
            get
            {
                return _Remark;
            }
            set
            {
                _Remark = value;
            }
        }

        //[Required]
        //[Range(0, 0]
        //[StringLength(0)]
        public Boolean IsActivated
        {
            get
            {
                return _IsActivated;
            }
            set
            {
                _IsActivated = value;
            }
        }

        //[Required]
        //[Range(0, 0]
        //[StringLength(0)]
        public Boolean IsLockedOut
        {
            get
            {
                return _IsLockedOut;
            }
            set
            {
                _IsLockedOut = value;
            }
        }

        #endregion

        #region Operators

        public void Update(User value)
        {
            // value.Id = Id;
            value.Name = Name;
            value.Username = Username;
            value.Remark = Remark;
            value.IsActivated = IsActivated;
            value.IsLockedOut = IsLockedOut;
        }

        public static implicit operator UserModel(User obj)
        {
            return new UserModel(obj);
        }

        public static implicit operator User(UserModel obj)
        {
            User value = new User();
            obj.Update(value);
            return value;
        }

        #endregion
    }
}
